<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
          <el-form-item label="数据通道名称" prop="keyword">
            <el-input v-model="queryParams.keyword" placeholder="请输入数据通道名称" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="审核状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
              <el-option label="正常" :value="0" />
              <el-option label="保存" :value="-1" />
              <el-option label="未审核" :value="2" />
              <el-option label="未测试" :value="3" />
              <el-option label="下架" :value="1" />
              <el-option label="审核失败" :value="-2" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

<!--        <el-row :gutter="10" class="mb8">-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['datasourceBase:add']">注册</el-button>-->
<!--          </el-col>-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['datasourceBase:edit']">修改</el-button>-->
<!--          </el-col>-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['datasourceBase:remove']">删除</el-button>-->
<!--          </el-col>-->
<!--          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--        </el-row>-->

        <el-table v-loading="loading" :data="DataBaseList" @selection-change="handleSelectionChange">
<!--        <el-table-column type="selection" width="55" align="center" />-->
        <el-table-column type="index" width="50" align="center" label="序号"></el-table-column>
        <el-table-column label="数据通道名称" align="center" prop="resourceName" width="180" />
        <el-table-column label="数据来源数量" align="center" prop="sourceNumber" width="180" />

        <el-table-column label="当前状态" align="center" prop="status">
          <template slot-scope="scope">
            <span v-if="scope.row.status === -2">审核失败</span>
            <span v-else-if="scope.row.status === -1">保存</span>
            <span v-else-if="scope.row.status === 0">正常(上架)</span>
            <span v-else-if="scope.row.status === 1">下架</span>
            <span v-else-if="scope.row.status === 2">未审核</span>
            <span v-else-if="scope.row.status === 3">未测试</span>
          </template>
        </el-table-column>
        <el-table-column label="简介" align="center" prop="brief" :show-overflow-tooltip="true" />
        <!-- <el-table-column label="详细介绍" align="center" prop="detail"/> -->

        <el-table-column label="录入用户" align="center" prop="createBy" />
        <el-table-column label="所属用户" align="center" prop="ownUserName">
          <template slot-scope="scope">
            <span>{{scope.row.ownUserName|| scope.row.createBy}}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属公司" align="center" prop="unit" />
        <el-table-column label="所属单位" align="center" prop="depart" />
        <!-- <el-table-column label="接口配置ID" align="center" prop="id" /> -->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-document" @click="handleDetail(scope.row)">查看详情</el-button>
<!--            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['datasourceBase:edit']" >修改</el-button>-->
<!--            <el-button size="mini" type="text" icon="el-icon-setting" @click="handleCheck(scope.row)" v-if="scope.row.status=='3' ? true : false">测试</el-button>-->
<!--            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['datasourceBase:remove']">删除</el-button>-->
<!--            <el-button size="mini" type="text" icon="el-icon-shopping-cart-2" @click="handleUp(scope.row)" v-if="(scope.row.status === 1 || scope.row.status === 0) ? true : false">{{ scope.row.status === 1 ? "上架" : "下架"}}</el-button>-->
          </template>
        </el-table-column>

        </el-table>

        <pagination v-show="baseTotal>0" :total="baseTotal" :page.sync="queryParams.currPage" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!--         添加或修改数据通道信息对话框-->
        <el-dialog :title="UpdateTitle" :visible.sync="UpdateOpen" width="1200px" append-to-body>
         <el-form>
           <el-form-item label="注册数据通道方式" prop="radio">
             <el-radio-group v-model="radio">
               <el-radio v-model="radio" :label="1" :disabled="disabled">人工注册</el-radio>
               <el-radio v-model="radio" :label="2" :disabled="disabled">文件注册</el-radio>
             </el-radio-group>
           </el-form-item>
         </el-form>
<!--          人工注册表单-->
          <el-form ref="baseAddForm" :model="baseAddForm" label-width="120px" v-if="radio===1" :rules="baseAddRules" >
           <el-row>
             <el-col :span="12">
               <el-form-item label="数据通道名称" prop="resourceName" required>
                 <el-input v-model="baseAddForm.resourceName" placeholder="请输入数据通道名称" />
               </el-form-item>
             </el-col>
             <el-col :span="12">
               <el-form-item label="所属公司" prop="unit" required>
                 <el-input v-model="baseAddForm.unit" placeholder="请输入所属公司" />
               </el-form-item>
             </el-col>
           </el-row>
             <el-row>
               <el-col :span="12">
                 <el-form-item label="所属单位" prop="depart">
                   <el-input v-model="baseAddForm.depart" placeholder="请输入所属单位" />
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                 <el-form-item label="引擎验证码" >
                   <el-input disabled></el-input>
                 </el-form-item>
               </el-col>

             </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="数据来源类型" required >
                  <el-select v-model="dataBaseType" multiple placeholder="请选择数据类型">
                    <el-option
                      v-for="item in dataBaseTypeList"
                      :key="item.dictLabel"
                      :label="item.dictLabel"
                      :value="item.dictLabel">
                    </el-option>
                  </el-select>

                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="数据来源数量" required>
                  <el-input-number v-model="baseAddForm.sourceNumber"></el-input-number>
                </el-form-item>
              </el-col>

            </el-row>
              <el-row>
                <el-form-item label="简介" prop="brief" required>
                  <el-input v-model="baseAddForm.brief" placeholder="请输入数据通道简介" type="textarea" maxlength="100" show-word-limit />
                </el-form-item>
              </el-row>
              <el-form-item label="详细介绍" prop="detail" required>
                <el-input v-model="baseAddForm.detail" placeholder="请输入数据通道详细介绍" type="textarea" maxlength="1000" show-word-limit />
              </el-form-item>

              <el-form-item label="展示图片" prop="iconUrl">
                <el-upload
                  class="upload-demo"
                  action=""
                  :multiple=false
                  :before-upload="handleIconUpload"
                  list-type="picture"
                  v-model="baseAddForm.iconUrl">
                  <el-button size="small" type="primary">点击上传</el-button>
                  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                </el-upload>
                <!-- 展示已选的图标文件 -->
                <div v-if="selectedIconFile">
                  <img :src="selectedIconFile.url" alt="已选图标" />
                </div>
              </el-form-item>
<!--          控制相关-->
          <el-form-item label="控制集">
            <el-tabs v-model="activeControlName" @tab-click="handleControlTab">
              <el-tab-pane label="可见控制" name="defaultControl" >
              <el-row>
                <el-form-item label="选择规则集" label-width="100px">
                  <el-select v-model="baseAddForm.controlRuleId" placeholder="请选择">
                   <el-option
                    v-for="item in rulesList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
              </el-row>
                <el-row>
                  <el-table :data="ruleList">
                    <el-table-column label="序号" align="center" prop="company" type="index"></el-table-column>
                    <el-table-column label="规则名称" align="center" prop="company"></el-table-column>
                    <el-table-column label="用户级别" align="center" prop="company" ></el-table-column>
                    <el-table-column label="用户类型" align="center" prop="company" ></el-table-column>
                    <el-table-column label="指定用户" align="center" prop="company" ></el-table-column>
                    <el-table-column label="可见性" align="center" prop="company" ></el-table-column>
                  </el-table>
                </el-row>

              </el-tab-pane>
              <el-tab-pane label="价格控制" name="priceControl">
                <el-row>
                  <el-form-item label="选择规则集" label-width="100px">
                    <el-select v-model="selectedRules" placeholder="请选择">
                      <el-option
                        v-for="item in rulesList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.label">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-table :data="ruleList">
                    <el-table-column label="序号" align="center" prop="company" type="index"></el-table-column>
                    <el-table-column label="规则名称" align="center" prop="company"></el-table-column>
                    <el-table-column label="用户级别" align="center" prop="company" ></el-table-column>
                    <el-table-column label="用户类型" align="center" prop="company" ></el-table-column>
                    <el-table-column label="指定用户" align="center" prop="company" ></el-table-column>
                    <el-table-column label="可见性" align="center" prop="company" ></el-table-column>
                  </el-table>
                </el-row>
              </el-tab-pane>
              <el-tab-pane label="使用控制" name="useControl">
                <el-row>
                  <el-form-item label="选择规则集" label-width="100px">
                    <el-select v-model="selectedRules" placeholder="请选择">
                      <el-option
                        v-for="item in rulesList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.label">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-table :data="ruleList">
                    <el-table-column label="序号" align="center" prop="company" type="index"></el-table-column>
                    <el-table-column label="规则名称" align="center" prop="company"></el-table-column>
                    <el-table-column label="用户级别" align="center" prop="company" ></el-table-column>
                    <el-table-column label="用户类型" align="center" prop="company" ></el-table-column>
                    <el-table-column label="指定用户" align="center" prop="company" ></el-table-column>
                    <el-table-column label="可见性" align="center" prop="company" ></el-table-column>
                  </el-table>
                </el-row>
              </el-tab-pane>
              <el-tab-pane label="获取控制" name="getControl">
                <el-row>
                  <el-form-item label="选择规则集" label-width="100px">
                    <el-select v-model="selectedRules" placeholder="请选择">
                      <el-option
                        v-for="item in rulesList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.label">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-table :data="ruleList">
                    <el-table-column label="序号" align="center" prop="company" type="index"></el-table-column>
                    <el-table-column label="规则名称" align="center" prop="company"></el-table-column>
                    <el-table-column label="用户级别" align="center" prop="company" ></el-table-column>
                    <el-table-column label="用户类型" align="center" prop="company" ></el-table-column>
                    <el-table-column label="指定用户" align="center" prop="company" ></el-table-column>
                    <el-table-column label="可见性" align="center" prop="company" ></el-table-column>
                  </el-table>
                </el-row>
              </el-tab-pane>
              <el-tab-pane label="安全控制" name="SecurityControl">
                <el-row>
                  <el-form-item label="选择规则集" label-width="100px">
                    <el-select v-model="selectedRules" placeholder="请选择">
                      <el-option
                        v-for="item in rulesList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.label">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-table :data="ruleList">
                    <el-table-column label="序号" align="center" prop="company" type="index"></el-table-column>
                    <el-table-column label="规则名称" align="center" prop="company"></el-table-column>
                    <el-table-column label="用户级别" align="center" prop="company" ></el-table-column>
                    <el-table-column label="用户类型" align="center" prop="company" ></el-table-column>
                    <el-table-column label="指定用户" align="center" prop="company" ></el-table-column>
                    <el-table-column label="是否确权" align="center" prop="company" ></el-table-column>
                    <el-table-column label="是否授权" align="center" prop="company" ></el-table-column>
                    <el-table-column label="是否加密" align="center" prop="company" ></el-table-column>
                    <el-table-column label="密码产生方式" align="center" prop="company" ></el-table-column>
                    <el-table-column label="密码保存方式" align="center" prop="company" ></el-table-column>
                  </el-table>
                </el-row>
              </el-tab-pane>
            </el-tabs>
          </el-form-item>
        </el-form>
        <el-form v-if="radio===2">
          <el-upload class="upload-demo"   :auto-upload="true" name="file"   action="" :before-upload="handleFileUpload" >
            <el-form-item label="数据通道文件" style="margin-bottom:0px">
              <el-button size="small" type="primary">选择数据通道文件</el-button>
            </el-form-item>
          </el-upload>
        </el-form>


          <div slot="footer" class="dialog-footer" prop="status">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
<!--         查看详情对话框-->
        <el-dialog :title="DetailTitle" :visible.sync="DetailOpen" width="1200px" append-to-body>
          <el-form ref="form" :model="baseDetailForm" >
            <el-form label-width="100px" :rules="rules" :model='baseDetailForm'>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="数据通道名称" prop="dataBaseName" >
                    <el-input v-model="baseDetailForm.resourceName" placeholder="请输入数据通道名称" :disabled="detailDisabled" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="所属公司" prop="company">
                    <el-input v-model="baseDetailForm.unit" placeholder="请输入所属公司"  :disabled="detailDisabled"/>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="所属单位" prop="department">
                    <el-input v-model="baseDetailForm.depart" placeholder="请输入所属单位"  :disabled="detailDisabled"/>
                  </el-form-item>
                </el-col>
              <el-col :span="12">
                <el-form-item label="引擎验证码">
                  <el-input disabled></el-input>
                </el-form-item>
              </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="数据来源数量">
                    <el-input disabled  v-model="baseDetailForm.sourceNumber"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="数据通道类型" >
                    <el-select v-model="dataBaseType" multiple placeholder="请选择数据类型" :disabled="detailDisabled">
                      <el-option
                        v-for="item in dataBaseTypeList"
                        :key="item.dictLabel"
                        :label="item.dictLabel"
                        :value="item.dictLabel">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-form-item label="简介" prop="brief">
                  <el-input v-model="baseDetailForm.brief" placeholder="请输入数据通道简介" type="textarea" maxlength="100" show-word-limit :disabled="detailDisabled"/>
                </el-form-item>
              </el-row>

              <el-form-item label="详细介绍" prop="detail">
                <el-input v-model="baseDetailForm.detail" placeholder="请输入数据通道详细介绍" type="textarea" maxlength="1000" show-word-limit :disabled="detailDisabled" />
              </el-form-item>

              <el-form-item label="展示图片" prop="iconUrl">
                <img :src="baseDetailForm.iconUrl" alt="无" width="50px" height="50px">
              </el-form-item>
          <!--          控制相关-->
<!--          <el-form-item label="可见控制规则">-->
<!--            <el-input v-model="baseDetailForm.controlRuleName" placeholder="请输入规则集名称"  :disabled="detailDisabled" />-->
<!--            <el-table>-->
<!--              <el-table-column label="序号" type="index"></el-table-column>-->
<!--              <el-table-column label="规则名称"></el-table-column>-->
<!--              <el-table-column label="用户类型"></el-table-column>-->
<!--              <el-table-column label="用户级别"></el-table-column>-->
<!--              <el-table-column label="指定用户"></el-table-column>-->
<!--              <el-table-column label="可见性"></el-table-column>-->
<!--            </el-table>-->
<!--          </el-form-item>-->
<!--            <el-form-item label="价格控制">-->

<!--            </el-form-item>-->
<!--            <el-form-item label="安全控制">-->

<!--            </el-form-item>-->
<!--            <el-form-item label="使用控制">-->

<!--            </el-form-item>-->
<!--            <el-form-item label="下载控制">-->

<!--            </el-form-item>-->
        </el-form>
      </el-form>


        </el-dialog>
      </el-col>
    </el-row>

  </div>
</template>

<script>

import {
  DataBaseAdd, DataBaseEdit,
  DataBaseFile, DatabaseInfoById,
  DataBaseInfoList,
  DataBaseTypeList, FileUpload,
  RuleList,
  RulesList
} from '@/api/qysj/app/DataBaseInfo'
import boxLayout from 'echarts/src/model/mixin/boxLayout'
import { buildCartesianSingleLabelElOption } from 'echarts/lib/component/axisPointer/viewHelper'
import axios from 'axios'
import fileUpload from '@/components/FileUpload/index.vue'
import { Form } from 'element-ui'

let id = 1000;

export default {
  name: "DataBaseInfo",
  data() {
  // const data = [{id: 1,label: "关键字:",},];
    return {
      // 查询数据通道参数
      queryParams:{
        keyword:'',
        status:0,
        pageSize:10,
        currPage:1
      },
      //显示搜索表单
      showSearch: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 注册/修改数据通道对话框
      UpdateOpen:false,
      UpdateTitle:'',

      // 查看详情对话框
      DetailOpen:false,
      DetailTitle:'',
      // 加载表格
      loading:true,
      // 数据通道列表
      DataBaseList:[],
      // 数据通道详情表单
      baseDetailForm:[],
      // 数据通道表单和校验规则
      baseAddForm:{},
      rules: {
        unit: [
          { required: true, message: "所属公司不能为空", trigger: "blur" },
        ],
        resourceName: [
          { required: true, message: "资源名称不能为空", trigger: "blur" },
        ],
        brief: [{ required: true, message: "简介不能为空", trigger: "blur" }],
        detail: [
          { required: true, message: "详细介绍不能为空", trigger: "blur" },
        ],
      },
      activeControlName:'defaultControl',
      activeRulesName:'1',
      activeRuleName:'1',
      // 数据通道类型列表
      dataBaseTypeList:[],
      // 选中的数据类型
      dataBaseType:[],
      // 选中的规则集
      selectedRules:'',
      // 规则集列表
      rulesList:[],
      // 规则列表
      ruleList:[],
      // 注册方式
      radio:1,
      disabled: false,
      // 数据通道注册表单验证
      baseAddRules:
        {
          resourceName: [
            { required: true, message: '请输入数据通道名称', trigger: 'blur' }
          ],
          brief: [
            { required: true, message: '请输入简介', trigger: 'blur' }
          ],
          detail: [
            {required: true, message: '请输入详情', trigger: 'blur' }
          ],
          unit: [
            {required: true, message: '请输入所属公司', trigger: 'blur' }
          ]
    },
      // 需要返回的数据通道注册数据
      // baseAddData:{},
      selectedIconFile: null, // 当前选中的图标文件
      detailDisabled:true,//查看详情表单禁用
      // 请求数据通道类型参数
      dataBaseTypeQuery:{
        dictType:'database_type'
      },
      // 数据通道总数
      baseTotal:0,
      // 多选框选中的id
      selIds:[]
    }
  },
  created() {
    this.getList();
    this.getDataBaseTypeList();
  },
  watch: {
    // 监听规则集变化
    selectedRules(newSelectedRules, oldSelectedRules) {
      console.log('选中的规则发生变化：', newSelectedRules);
      this.baseAddForm.rulesName=newSelectedRules;

      // 请求后端 根据规则集请求对应规则 展示

    },
  },
  methods:{
    // 表单重置
    // 表单重置
    reset() {
      (this.dataStructId = ""),
        (this.datasourceContentList = [{name: null,tableName: null,dataType: null,remark: null,sourceId: null,},]),
        (this.baseAddForm = {
          userId: null,brief: null,iconUrl: null,
          datasourceDefaultControlList: [
            {userId: null,userType: null,userLevel: null,sharedType: null,isVisible: null,remark: null,sourceId: null,dataEnsureRightType: null,dataFreedomType: null,},
          ],
          datasourceDefaultPriceList: [
            {userId: null,userType: null,userLevel: null,billingType: null,usePeriod: null,productUnit: null,price: null,remark: null,},
          ],
          datasourceInterface: {
            sourceTypes: null,sourceCategory: null,isAgent: null,databaseAlias: null,databaseName: null,userName: null,password: null,ipaddress: null,port: null,
            contentType: null,engineSerial: null,header: null,method: null,system: null,version: null,url: null,authCode: null,engineId: null,
          },
          detail: null,
          inputUserId: null,
          keyword: null,
          ownUserId: null,
          status: null,
          unit: null,
          defaultPwd: null,
          pwdSaveType: null,
          pwdType: null,
          datasourceContentList: [{name: null,tableName: null,dataType: null,remark: null,sourceId: null,},],
          datasourceStructList: [{classAlias: null,representation: null,remark: null,datasourceContentList: [],},],
          typeIdList: [],
        });
      this.resetForm("form");
    },
    getRulesList(){
      RulesList().then(res=>{
        this.rulesList=res.data;
      })
    },
    // 获取数据类型列表
    getDataBaseTypeList(){
      DataBaseTypeList(this.dataBaseTypeQuery).then(res=>{
        this.dataBaseTypeList=res.data;
      })
    },
    getList(){
      this.loading=true;
      DataBaseInfoList(this.queryParams).then(res=>{
        this.DataBaseList=res.rows;
        this.baseTotal=res.total;
        this.loading=false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");//全局方法
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      this.UpdateOpen = true;
      this.title = "注册数据通道基本信息";
      this.getRulesList()
    },
    // 修改按钮操作
    handleUpdate(data){
      const id = data.id || this.selIds;
      DatabaseInfoById(id).then(res=>{
       if (res.code===200){
         this.baseAddForm=res.data;
         if (this.baseAddForm.dataBaseType&&this.baseAddForm.dataBaseType.length>0){
           this.dataBaseType=this.baseAddForm.databaseType.split(',')
         }

         this.UpdateTitle="修改数据通道信息"
         this.UpdateOpen=true;
       }else {
         this.$message('获取数据通道信息失败')
       }
      })

    },

    //TODO 删除数据通道（单个或多个）
    // 删除按钮操作
    handleDelete(){

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      // console.log('selection', selection)
      this.selIds = selection.map((item) => item.id);
      // console.log('selItems', this.selItems)
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 查看数据通道详情
    handleDetail(data){
      this.baseDetailForm=data;
      console.log('data', data)
      if (this.baseDetailForm.dataBaseType&&this.baseDetailForm.dataBaseType.length>0){
        this.dataBaseType=this.baseDetailForm.databaseType.split(',')
      }
      this.DetailOpen=true;
      this.DetailTitle='查看数据通道详情';
    },
    //TODO 测试数据通道
    // 测试数据通道
    handleCheck(){
      console.log('测试数据通道')
    },
    //TODO 上架下架数据通道
    handleUp(){
      console.log('上架' )
    },
    // 注册/修改数据通道对话框涉及的事件
    handleControlTab(tab){
      console.log('tab', tab)
    },
    // 提交按钮
    submitForm(){
      const baseAddFormInstance=this.$refs.baseAddForm;
      // 进行表单验证
      baseAddFormInstance.validate(valid=>{

        if (valid&&this.dataBaseType.length>0){
          this.baseAddForm.databaseType=this.dataBaseType.join(',');
          // const baseAddData = new FormData();
          // for (const key in this.baseAddForm) {
          //     baseAddData.append(key, this.baseAddForm[key]);
          // }
          if (this.baseAddForm.id){
            DataBaseEdit(JSON.stringify(this.baseAddForm)).then(res=>{
              if (res.code===200){
                this.$message('修改成功')
                this.UpdateOpen=false;
                this.baseAddForm={}
              }
            })
          }else {
            // 新增数据通道
            DataBaseAdd(JSON.stringify(this.baseAddForm)).then(res=>{
              if (res.code===200){
                this.$message('注册成功！')
                this.UpdateOpen=false;
                this.baseAddForm={}
              }else {
                this.$message(res.data.msg)
              }
            })
          }
        }else {
          if (this.dataBaseType.length===0){
            this.$message('请至少选择1个数据通道类型')
          }
        }
      })
    },
    // icon上传
    handleIconUpload(file){
      const form=new FormData()
      form.append('file',file);
      FileUpload(form).then(res=>{
        if (res.code===200){
          this.baseAddForm.iconUrl=res.url;
        }
      })
      this.selectedIconFile=file
      return false;
    },

    // 取消按钮
    cancel(){
      this.baseAddForm={}
      this.UpdateOpen=false;
    },
    // 文件上传注册
    handleFileUpload(file){
      console.log('event,file', file)
      const BaseFile=new FormData()
      BaseFile.append('file',file);
      DataBaseFile(BaseFile).then(res=>{
        if (res.data.code===200){
          this.$message('注册成功！')
          this.UpdateOpen=false;

        }else {
          this.$message(res.data.msg)
        }
      })
    }
  }
};
</script>
<style>
.el-row{
  margin-bottom: 10px;
}
</style>
